#pragma once

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <stdarg.h>



enum MsgLevel {FATAL,_ERROR,WARNING,DEBUG,INFO};

struct rpsColumn{
	MsgLevel MessageLevel;
	FILE* destFile;
	char* msgText;
	CRITICAL_SECTION columnAccess;
};

DWORD WINAPI LoggerManager(PVOID pvParam);

class RingBuffer
{
public:
	static const int rpsSize = 64;
	LONG rpsIter;
	LONG unprocRec;
	rpsColumn sharedRps[rpsSize];
	HANDLE eventWriteToRpsDone[rpsSize];
	HANDLE eventWriteToFileDone[rpsSize];
public:
		static RingBuffer& const TryToCreate()
        {
                static RingBuffer theSingleInstance;
                return theSingleInstance;
        }
private:        
        RingBuffer(){
		for(int i = 0;i<rpsSize;i++){
			InitializeCriticalSection(&sharedRps[i].columnAccess);
			eventWriteToRpsDone[i]  = CreateEvent(NULL,TRUE,FALSE,NULL); 
			eventWriteToFileDone[i] = CreateEvent(NULL,TRUE,FALSE,NULL); 
		}
		CreateThread(NULL,0,LoggerManager,NULL,NULL,NULL);
}

RingBuffer(RingBuffer& root){}
RingBuffer& operator=(RingBuffer&){}
};		

class Logger{
private:
	RingBuffer *buf;
	MsgLevel Filter;
	FILE* Output;
	static const unsigned int MaxMsgLength = 300;
public:
	~Logger();
	Logger();
	Logger(FILE *out);
	Logger(MsgLevel filter);
	Logger(FILE *out,MsgLevel filter);
	//int Error	(char* message, ... );
	//int Warning	(char* message, ... );
	int Debug	(char* message, ... );
	//int Fatal	(char* message, ... );
	//int Info	(char* message, ... );
};




























